package com.sgb.kjwl.view.widget;

import android.content.Context;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;

import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.supplier3.DictEntity3;
import com.sgb.kjwl.view.ui.adapter.DictAdapter3;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.PopViewHolder;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;
import com.swgk.core.recyclerview.decoration.RecyclerCustomDecoration;

import java.util.List;

//多选下拉框样式一
public class MultiWindow3 extends BasePopWindow {

    private RecyclerView recyclerView;
    private DictAdapter3 dictAdapter;
    private List<DictEntity3> dictEntityList;
    private OnCallBack onCallBack;
    private OnCloseBack onCloseBack;

    public MultiWindow3(Context context) {
        super(context);
    }

    @Override
    protected int popLayout() {
        return R.layout.popwindow_multi3;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        recyclerView = holder.getPop().findViewById(R.id.rlv_list);
        bgView = holder.getPop().findViewById(R.id.cover_layout);
        bgView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dissMiss();
            }
        });
        dictAdapter = new DictAdapter3(mContext, null);
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        recyclerView.addItemDecoration(new RecyclerCustomDecoration(0,
                0,
                0,
                mContext.getResources().getDimension(R.dimen.dp1), mContext.getResources().getColor(R.color.color_line)));
        recyclerView.setAdapter(dictAdapter);
        dictAdapter.setOnItemClick(new AdapterOnItemClick<DictEntity3>() {
            @Override
            public void onItemClick(DictEntity3 dictEntity, int position) {
                if (onCallBack != null) {
                    onCallBack.result(dictEntity);
                }
                dissMiss();
            }
        });
    }

    public void setData(List<DictEntity3> dictEntityList) {
        this.dictEntityList = dictEntityList;
        dictAdapter.setDatas(dictEntityList);
    }

    @Override
    public void dismiss() {
        super.dismiss();
        if (onCloseBack != null) {
            onCloseBack.dismiss();
        }
    }

    public interface OnCallBack {
        void result(DictEntity3 dictEntity);
    }

    public void setOnCallBack(OnCallBack onCallBack) {
        this.onCallBack = onCallBack;
    }

    public interface OnCloseBack {
        void dismiss();
    }

    public void setOnCloseBack(OnCloseBack onCloseBack) {
        this.onCloseBack = onCloseBack;
    }
}
